﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Model
{
    /// <summary>
    /// RESPONSABILITY: - data bucket
    ///                 - add, remove tasks 
    ///                 - estimate the cost of a project
    /// </summary>
    public class Project
    {
        public string ProjectCode { get; set;}
        public List<ITask> Tasks;
        IDGenerator idGenerator =IDGenerator.Instance;

        public double EstimatedCost 
        {
            get
            {
                double estimatedCost = 0;
                foreach (ITask task in this.Tasks)
                {
                    estimatedCost += task.EstimateCost();
                }
                return estimatedCost;
            } 
        }

        public int ProjectId { get; private set; }
        static private List<int> projectsIds{get;set;}
       

        private int ProjectId_Generator()
        {

            Type type = typeof(Project);
            return idGenerator.RandomIDGenerator(type);
        }

        public Project(string projectCode)
        {
            this.ProjectCode = projectCode;
            projectsIds = new List<int>();
            Tasks = new List<ITask>();


            ProjectId = ProjectId_Generator();
            projectsIds.Add(ProjectId);
        }

        public void AddTaskToProject(ITask task)
        {
            this.Tasks.Add(task);
            
        }

        public void RemoveTaskFromProject(ITask task)
        {
            this.Tasks.Remove(task);
        }

        public IEnumerable<ITask> GetAllTasks()
        {
            return this.Tasks;
        }    
    }
}
